package com.eascs.web.p2p.action;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.p2p.common.service.IMsgSmsService;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.p2p.common.vo.MsgSmsQueryVO;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.tag.MenuTag;
import com.eascs.web.p2p.common.BaseMasterViewController;

@Controller
@RequestMapping("/sms")
public class SmsController extends BaseMasterViewController {

	@Reference
	IMsgSmsService msgSmsService;
	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "SmsManerger");
	}

	/**
	 * @Title: index
	 * @Description: 短信列表
	 * @author 张庆奇
	 * @param vo
	 * @return
	 * @return String
	 * @throws
	 * @date 2016年8月1日 上午9:34:43
	 */
	@RequestMapping(value = "/index")
	public String index(MsgSmsQueryVO vo) {

		vo.setPageSize(10);
		ModelResult<PageResult<Object[]>> model = msgSmsService.page(vo);
		PageResult<Object[]> pageResult = new PageResult<Object[]>();
		if (model.isSuccess()) {
			pageResult = model.getModel();
		}

		String[] titles = { "短信类型", "模板code", "接收人手机号码","短信内容", "状态" };

	
		String pageUrl = "/sms/index";
		pageUrl = UrlUtil.appendUrl(pageUrl, "templateCode", vo.getTemplateCode());
		pageUrl = UrlUtil.appendUrl(pageUrl, "phone", vo.getPhone());
		pageUrl = UrlUtil.appendUrl(pageUrl, "templateType", vo.getSmsType());
		pageUrl = UrlUtil.appendUrl(pageUrl, "smsStatus", vo.getSmsStatus());
		pageUrl = UrlUtil.appendUrl(pageUrl, "showPage", "");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl);
		paginationInfo.setBuildPagingNavigation(true);
		// paginationInfo.setFirstRenderColumnIndex(1);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);

		BaseRestResult.refresh();
		return "/sms/index";
	}

	
}
